package com.pengtu.gsj.controller.dl;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.pengtu.gsj.controller.base.BaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.dl.RoadBasicInfo;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.dl.RoadbasicinfoService;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

/**
 * 
 * 
 * RoadBasicInfoController
 * 
 * 2017年5月11日 下午5:14:49
 * 
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping("/roadBasicInfo/")
public class RoadBasicInfoController extends BaseController {

	@Autowired
	private RoadbasicinfoService roadbasicinfoService;
	
	/**
	 * 
	 * getRoadBasicInfos:
	 * 适用:按属性要求获取码表列表
	 * @param page 对象集
	 * @param request
	 * @param model 传递参数
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@ResponseBody
	@RequestMapping(value = "list", produces = "application/json; charset=utf-8")
	public Page<RoadBasicInfo> getRoadBasicInfos(Page<RoadBasicInfo> page,
			HttpServletRequest request, Model model) {
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("type,roadName,startPegNum");
			page.setOrder("asc,asc,asc");
		}
		page = roadbasicinfoService.findRoadbasicinfos(page, queryFilter);
		return page;
	}
	
	/**
	 * 
	 * loadEntity:
	 * 适用: 每个方法执行之前都会执行该方法
	 * @param id  RoadBasicInfo主键id
	 * @return 返回持久对象RoadBasicInfo或者新创建对象
	 * @exception 
	 * @since  1.0.0
	 */
	@ModelAttribute
	public RoadBasicInfo loadEntity(String id,Model model){
		RoadBasicInfo roadbasicinfo ;
		if (StringUtils.isNotEmpty(id)) {
			roadbasicinfo = roadbasicinfoService.getRoadbasicinfo(id);
		}else {
			roadbasicinfo = new RoadBasicInfo();
		}
		model.addAttribute("top", SpringMvcUtils.getParameter("top"));
		model.addAttribute("left", SpringMvcUtils.getParameter("left"));
		return roadbasicinfo;
	}
	
	/**
	 * 
	 * saveRoadBasicInfo:
	 * 适用:保存对象
	 * @param roadbasicinfo 对象
	 * @param request 请求
	 * @param model 传递参数
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "save",method=RequestMethod.POST)
	@Token(remove = true)
	public String saveRoadBasicInfo(@ModelAttribute RoadBasicInfo roadbasicinfo,RedirectAttributes attributes,Model model) {
			roadbasicinfoService.saveRoadbasicinfo(roadbasicinfo);
			attributes.addFlashAttribute("msg", "保存成功！");
			attributes.addAttribute("top",	SpringMvcUtils.getParameter("top"));
			attributes.addAttribute("left", SpringMvcUtils.getParameter("left"));
		return "redirect:/roadBasicInfo/show.do";
	}
	
	
	/**
	 * 
	 * deleteRoadBasicInfo:删除对象
	 * 适用:
	 * @param id 唯一参数标识
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "delete")
	public String deleteRoadBasicInfo(String id,RedirectAttributes attributes){
		roadbasicinfoService.deleteRoadbasicinfo(id);
		attributes.addFlashAttribute("msg", "删除成功！");
		attributes.addAttribute("top",	SpringMvcUtils.getParameter("top"));
		attributes.addAttribute("left", SpringMvcUtils.getParameter("left"));
		return "redirect:/roadBasicInfo/show.do";
	}
	
	/**
	 * 
	 * roadbasicinfoShow:展示页面
	 * 适用:
	 * @param model 传递参数
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("show")
	public String roadBasicInfoShow(Model model) {
		String msg = SpringMvcUtils.getParameter("msg");
		if (StringUtils.isNotEmpty(msg)) {
			model.addAttribute("msg", msg);
		}
		return "dl/roadBasicInfo";
	}
	
	/**
	 * 
	 * roadbasicinfoInput:新增页面
	 * 适用:
	 * @param id 唯一id标识
	 * @param model 传递参数
	 * @return 新增/修改页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("input")
	@Token(save = true)
	public String roadbasicinfoInput(@ModelAttribute RoadBasicInfo roadbasicinfo,RedirectAttributes attributes,Model model){
		if(roadbasicinfo!=null){
			model.addAttribute("entity", roadbasicinfo);
		}
		attributes.addAttribute("top",	SpringMvcUtils.getParameter("top"));
		attributes.addAttribute("left", SpringMvcUtils.getParameter("left"));
		return "dl/roadBasicInfoInput";
	}

	
}
